<template>
  <PublicPage :pageName="routeData.spuId?'编辑商品':'添加商品'" :borderType="true" :showNav="true">
    <view class="addProduct_layout">
    <scroll-view class="addProduct_msg_box" scroll-y="true" -webkit-overflow-scrolling="touch" scroll-with-animation="true">
        <div class="goods_msg_con">
          <view class="helpSell_content_box" style="margin-bottom: 0rpx" v-if="operatorIDArr.includes(userInfo.accountId)&&!routeData.spuId">
            <view class="helpSell_box">
              <view class="helpSell_box_l">
                <span>是否给他人添加商品</span>
              </view>
              <view class="helpSell_box_r">
                <u-switch
                  class="switch_button"
                  active-color="#E44435"
                  inactive-color="#ccc"
                  v-model="isoperatorAddType"
                  @change="setOperatorFn"
                ></u-switch>
              </view>
            </view>
          </view>
          <div class="goods_msg_box" v-if="isoperatorAddType">
            <div class="goods_msg_left">用户ID<i>*</i></div>
            <div class="goods_msg_right">
              <input class="input_box" type="text" maxlength="50" v-model.trim="addAccountId" placeholder="请输入用户ID" placeholder-style="color:#C8C9CC;">
            </div>
          </div>
          <div class="goods_msg_box goods_msg_box_start">
            <div class="goods_msg_left">商品标题<i>*</i></div>
            <view class="textarea_wrap">
              <textarea
                  v-model="pageData.goodsSpuVO.goodsName"
                  type="text"
                  maxlength="100"
                  auto-height
                  placeholder="请输入商品名称"
                  placeholder-style="color:#C8C9CC;"
                  class="textarea_box"
                  @input="(e) => maxLengthInputFn(e,'goodsName',100)"
              ></textarea>
            </view>
<!--            <div class="goods_msg_right goods_title_rt">-->
<!--            </div>-->
          </div>
          <div class="goods_msg_box goods_msg_box_start">
            <div class="goods_msg_left">商品描述</div>
            <view class="textarea_wrap u-p-0">
              <textarea
                  v-model="pageData.goodsSpuVO.description"
                  type="text"
                  maxlength="200"
                  auto-height
                  placeholder="请输入商品描述"
                  placeholder-style="color:#C8C9CC;"
                  class="textarea_box description_box"
                  @input="(e) => maxLengthInputFn(e,'description',200)"
              ></textarea>
            </view>
          </div>
          <div class="goods_msg_box">
            <div class="goods_msg_left">价格<em>(￥)</em><i>*</i></div>
            <div class="goods_msg_right">
              <div class="salePrice_box" v-if="specificList.goodsSpecValuesVOList&&specificList.goodsSpecValuesVOList.length>0" @click.stop="addSpecsFn">
                {{quantityData.salePriceMin==quantityData.salePriceMax?quantityData.salePriceMax:quantityData.salePriceMin+'~'+quantityData.salePriceMax}}
              </div>
              <input v-else class="input_box" type="digit" maxlength="10" v-model.trim="pageData.goodsSpuVO.salePrice" @input="(e) => inputFn(e, 'salePrice')" @blur="(e) => blurFn(e, 'salePrice')" placeholder="请输入商品价格" placeholder-style="color:#C8C9CC;">
            </div>
          </div>
          <div class="goods_msg_box u-p-b-0">
            <div class="goods_msg_left">商品主图</div>
          </div>
          <div class="upload_img_box">
            <ul class="upload_img_ul">
              <li class="upload_img_li" v-for="(img, imgIndex) in pageData.goodsSpuVO.images" :key="imgIndex" @click.stop="previewMediaFn(pageData.goodsSpuVO.images,imgIndex)">
                <div class="cover_tab_box" v-if="imgIndex==0">封面</div>
                <img class="img_box" mode="scaleToFill" :src="coverImgHandleFn(img.url,100,100)" alt="img">
                <div class="close_icon_box" hover-class='hover' @click.stop="closeFn(imgIndex)"><img src="https://image.qqpyyds.com/mpAppImg/icon/error2_icon.png" alt="close_icon"></div>
              </li>
              <li class="upload_img_li upload_img_li_btn" @click.stop="uploadImgFn" v-if="pageData.goodsSpuVO.images.length<9">
                <em class="iconfont icon-camera_fill2 iconfont_fill2"></em>
              </li>
            </ul>
          </div>
        </div>

        <view class="helpSell_content_box">
          <view class="helpSell_box">
            <view class="helpSell_box_l">
              <span>开启帮卖</span>
            </view>
            <view class="helpSell_box_r">
              <u-switch
                class="switch_button"
                active-color="#E44435"
                inactive-color="#ccc"
                v-model="isHasHelpSell"
                @change="setHelpSellFn"
              ></u-switch>
            </view>
          </view>
          <view class="helpSell_box" v-if="isHasHelpSell">
            <view class="helpSell_box_l"><i>帮卖佣金</i><view class="span">*</view><b>(预计{{commissionAmountLv1 || '0.00'}}元)</b></view>
            <view class="helpSell_box_r">
              <view class="helpSell_ratio_box">
                占商品售价比例
                <input class="input_box" type="digit" v-model="pageData.goodsSpuVO.commissionRatioLv1" @input="(e) => inputFn(e, 'commissionRatioLv1')" @blur="(e) => blurFn(e, 'commissionRatioLv1')" maxlength="5" placeholder="0" placeholder-style="color:#C8C9CC;">
                %
              </view>
            </view>
          </view>
          <!-- <view class="helpSell_box" v-if="isHasHelpSell">
            <view class="helpSell_box_l"><i>二级佣金</i><em class="iconfont icon-question" @click.stop="commissionTipsType = true"></em><b>(预计{{commissionAmountLv2 || '0.00'}}元)</b></view>
            <view class="helpSell_box_r">
              <view class="helpSell_ratio_box">
                占一级佣金比例
                <input class="input_box" type="digit" maxlength="5" v-model="pageData.goodsSpuVO.commissionRatioLv2" @input="(e) => inputFn(e, 'commissionRatioLv2')" @blur="(e) => blurFn(e, 'commissionRatioLv2')" placeholder="80" placeholder-style="color:#C8C9CC;">
                %
              </view>
            </view>
          </view> -->
        </view>

        <div class="goods_msg_con">
          <div class="goods_msg_box goods_msg_box_r" @click.stop="openFreightFn(1)">
            <div class="goods_msg_left">物流方式</div>
            <div class="goods_msg_right">{{pageData.goodsSpuVO.freightType==1?"快递(全国包邮)":"无需物流"}}<em class="iconfont icon-arrow_right arrow_box"></em></div>
          </div>
        </div>
        <div class="goods_msg_con">
          <div class="goods_msg_box goods_msg_box_r" @click.stop="_goEditGoods">
            <div class="goods_msg_left">商品详情页</div>
            <div class="goods_msg_right" v-if="goodsDetailsHtml"><span>已设置</span><em class="iconfont icon-arrow_right arrow_box"></em></div>
            <div class="goods_msg_right" v-else><span style="color:#C8C9CC;">卖点描述越详细，越有吸引力</span><em class="iconfont icon-arrow_right arrow_box"></em></div>
          </div>
        </div>
        <div class="goods_msg_con goods_msg_con_two">
          <div class="goods_msg_box goods_msg_box_r" @click.stop="notRequiredType=!notRequiredType">
            <div class="goods_msg_left">更多设置</div>
            <div class="goods_msg_right goods_msg_right_w">
              <em class="iconfont icon-arrow_right arrow_box" :class="!notRequiredType?'notRequired_img_t':'notRequired_img_b'"></em>
            </div>
          </div>
        </div>
        <div class="goods_msg_con goods_msg_con_not" v-if="notRequiredType">
          <div class="goods_msg_box">
            <div class="goods_msg_left">划线价<em>(￥)</em></div>
            <div class="goods_msg_right">
              <input class="input_box" type="digit" maxlength="200" v-model.trim="pageData.goodsSpuVO.marketPrice" @input="(e) => inputFn(e, 'marketPrice')" @blur="(e) => blurFn(e, 'marketPrice')" placeholder="划线价建议高于商品价格" placeholder-style="color:#C8C9CC;">
            </div>
          </div>
          <div class="goods_msg_box">
            <div class="goods_msg_left">成本价<em>(￥)</em></div>
            <div class="goods_msg_right">
              <div class="costPrice_box" v-if="specificList.goodsSpecValuesVOList.length>0" @click.stop="addSpecsFn">
                <span v-if="quantityData.costPriceMin>0">{{quantityData.costPriceMin==quantityData.costPriceMax?quantityData.costPriceMax:quantityData.costPriceMin+'~'+quantityData.costPriceMax}}</span>
                <span v-else>用于利润核算，仅团长可见</span>
              </div>
              <input v-else class="input_box" type="digit" maxlength="200" v-model.trim="pageData.goodsSpuVO.costPrice" @input="(e) => inputFn(e, 'costPrice')" @blur="(e) => blurFn(e, 'costPrice')" placeholder="用于利润核算，仅团长可见" placeholder-style="color:#C8C9CC;">
            </div>
          </div>
          <div class="goods_msg_box goods_msg_box_f">
            <div class="goods_msg_left">规格</div>
            <div class="goods_msg_right goods_msg_right_textR">
              <ul class="opt_spec_list" v-if="selectedSpec.length>0" @click.stop="addSpecsFn">
                <li class="opt_spec_li" v-for="(itemSpec, itemSpecIndex) in selectedSpec" :key="itemSpecIndex">
                  <span>{{itemSpec.specName}}:</span>
                  <i v-for="(specValue, specValueIndex) in itemSpec.goodsSpecValuesVOList" :key="specValueIndex">
                    {{specValue.specValue}}
                    <em>,</em>
                  </i>
                </li>
              </ul>
              <div class="addSpecs_box" hover-class='hover' @click.stop="addSpecsFn">
                <span v-if="selectedSpec && !selectedSpec.length">添加多规格</span>
                <i class="iconfont icon-arrow_right arrow_box"></i>
              </div>
              <!-- <input v-else class="input_box input_box_z" type="digit" maxlength="200" v-model.trim="pageData.goodsSpuVO.specName" placeholder="请输入单个规格名称"> -->
              <!-- <button class="goods_msg_redBtn" hover-class='hover' @click.stop="addSpecsFn">添加多规格</button> -->
            </div>
          </div>
          <div class="goods_msg_box">
            <div class="goods_msg_left">库存</div>
            <div class="goods_msg_right">
              <div class="quantity_box" @click.stop="addSpecsFn" v-if="specificList.goodsSpecValuesVOList.length>0">
                <i>{{specificList.goodsSpecValuesVOList.length}}个规格，</i>
                <span>{{quantityData.type==0?'共'+quantityData.quantityAmount+'个':'不限'}}</span>
              </div>
              <input class="input_box" v-else type="number" maxlength="10" @input="(e)=>quantityInputFn(e)" v-model.trim="pageData.goodsSpuVO.quantity" placeholder="不限" placeholder-style="color:#C8C9CC;">
            </div>
          </div>
          <div class="goods_msg_box goods_msg_box_f" @click.stop="classifyPopupShow=true">
            <div class="goods_msg_left">分类</div>
            <div class="goods_msg_right" hover-class='hover'>
              <i class="choiceClassify_box" v-if="choiceClassifyData.name">{{choiceClassifyData.name}}</i>
              <span v-else>未分类</span>
              <i class="iconfont icon-arrow_right arrow_box"></i>
            </div>
          </div>
          <!-- <div class="goods_msg_box goods_msg_box_f">
            <div class="goods_msg_left">标签</div>
            <div class="goods_msg_right" hover-class='hover' @click.stop="addlabelFn">
              <ul class="selected_label_box" v-if="selectedLabel.length>0">
                <li v-for="(label, labelIndex) in selectedLabel" :key="labelIndex">{{label.name}}</li>
              </ul>
              <span v-else>添加标签会有效提升购买</span>
            </div>
          </div> -->
          <!-- <div class="goods_msg_box goods_msg_box_f">
            <div class="goods_msg_left">商品编码</div>
            <div class="goods_msg_right goods_msg_right_textR">
              <input class="input_box" type="number" maxlength="100" v-model.trim="pageData.goodsSpuVO.sn" placeholder="用于供应链订单统计和追踪">
            </div>
          </div> -->
        </div>
    </scroll-view>
    <button class="buttonStyleNone fixedBottomBtn" :disabled="addGoodsDisabled" hover-class='hover' v-if="routeData.spuId" @click.stop="addGoodsFn(1)">编辑保存</button>
    <button class="buttonStyleNone fixedBottomBtn" :disabled="addGoodsDisabled" hover-class='hover' v-else @click.stop="addGoodsFn(0)">确认添加</button>
    <!-- 选择分类弹窗 -->
    <u-popup v-model="classifyPopupShow" mode="bottom" :closeable="true" border-radius="24">
      <view class="popup_content_box">
        <view class="popup_content_title">选择商品分类</view>
        <scroll-view class="popup_content_msg classify_box" :scroll-y="true">
          <ul class="classify_ul_box">
            <li class="classify_li_box" v-for="(classify, classifyIndex) in userCategory" :key="classifyIndex" @click.stop="choiceClassifyFn(classifyIndex)">
              <div class="classify_li_l">{{classify.name}}</div>
              <div class="classify_li_r">
                <img class="img_box" v-if="categoryIndex==classifyIndex" src="https://image.qqpyyds.com/mpAppImg/icon/success2_icon.png" alt="">
                <img class="img_box" v-else src="https://image.qqpyyds.com/mpAppImg/icon/yuanxing1_icon.png" alt="">
              </div>
            </li>
          </ul>
        </scroll-view>
        <view class="popup_btn_box">
          <button class="confirm_btn_box" hover-class="hover" @click.stop="defineClassifyFn">确定</button>
        </view>
      </view>
    </u-popup>
    <!-- 选择分类弹窗 -->
    <u-popup v-model="logisticsShow" mode="bottom" :closeable="true" border-radius="24" @close="logisticsCloseFn()">
			<view class="popup_content_box">
        <view class="popup_content_title">选择物流方式</view>
        <view class="popup_content_msg">
          <!-- 物流方式 -->
          <view class="mode_type_box" @click.stop="choiceFreightFn(1)">
            <view class="mode_type_l">快递(全国包邮)</view>
            <view class="mode_type_r">
              <img class="img_box" v-if="freightType==1" src="https://image.qqpyyds.com/mpAppImg/icon/success2_icon.png" alt="">
              <img class="img_box" v-else src="https://image.qqpyyds.com/mpAppImg/icon/yuanxing1_icon.png" alt="">
            </view>
          </view>
          <view v-if="freightType==1" class="logistics_template_box items-center justify-between">
            <view class="linh-20 viceColorN7">运费模板</view>
            <view class="items-center linh-20 viceColor" @click="navigateTo({url: '/pagesB/freightTemplate/selectTemplate'})"><text>已选“运费模板名称”</text><i class="iconfont icon-arrow_right fz-14" /></view>
          </view>
          <!-- 物流方式 -->
          <!-- 无需物流 -->
          <view class="mode_type_box" @click.stop="choiceFreightFn(2)">
            <view class="mode_type_l">无需物流</view>
            <view class="mode_type_r">
              <img class="img_box" v-if="freightType==2" src="https://image.qqpyyds.com/mpAppImg/icon/success2_icon.png" alt="">
              <img class="img_box" v-else src="https://image.qqpyyds.com/mpAppImg/icon/yuanxing1_icon.png" alt="">
            </view>
          </view>
          <view v-if="freightType==2">
            <view class="mode_type_box noNeed_mode_box">
              <view class="mode_type_l">需要买家填写以下信息</view>
            </view>
            <view class="mode_type_box noNeed_mode_box">
              <view class="mode_type_l">联系人</view>
              <view class="mode_type_r">
                <img class="img_box" src="https://image.qqpyyds.com/mpAppImg/icon/success1_icon.png" alt="">
              </view>
            </view>
            <view class="mode_type_box noNeed_mode_box">
              <view class="mode_type_l">手机号</view>
              <view class="mode_type_r">
                <img class="img_box" src="https://image.qqpyyds.com/mpAppImg/icon/success1_icon.png" alt="">
              </view>
            </view>
          </view>
          <!-- 无需物流 -->
        </view>
        <view class="popup_btn_box">
          <button class="confirm_btn_box" @click.stop="openFreightFn(2)" hover-class="hover">确定</button>
        </view>
      </view>
		</u-popup>


    <!-- 帮卖佣金提示弹窗 -->
    <u-popup v-model="commissionTipsType" mode="center" :zoom="false" border-radius="16">
      <view class="tips_popup_box">
        <view class="tips_popup_title linh-40 u-p-t-30">二级佣金为选填</view>
        <view class="tips_popup_title linh-40 u-p-b-30">二级佣金<text class="themeFontColor">从一级佣金中支出</text></view>
        <view class="tips_popup_btn">
          <button class="iKnow_btn" hover-class='hover' @click.stop="commissionTipsType = false">知道了</button>
        </view>
      </view>
    </u-popup>
    <!-- 帮卖佣金提示弹窗 -->
  </view>
    <!-- 关注公众号弹框 -->
<!--    <attendOfficial-->
<!--        v-if="dlAttendOfficial"-->
<!--        :show="dlAttendOfficial"-->
<!--        text="关注公众号第一时间收到商品销售信息"-->
<!--        :isRefresh="true"-->
<!--        @close="dlAttendOfficial=false"-->
<!--    />-->
    <!-- 分享海报绘制 -->
    <OpenGroupSharing ref="shareChild" @shareSuccess="_shareSuccess" />
  </PublicPage>
</template>

<script>
import PublicPage from '@/components/publicPage/index.vue'
// import attendOfficial from '@/components/attendOfficial/index.vue'
import { upload } from '../../components/ossutil/ossMult'
import goodsApi from "@/api/goods.js"
import Util from "@/api/util.js"
import OpenGroupSharing from "@/components/shareImage/openGroupSharing.vue"
export default {
  components: {PublicPage,OpenGroupSharing},
  data () {
    return {
      // 运营者ID为了能帮他人上传商品
      operatorIDArr: ['1476020797292281858','1475475300085280770','1475660013076914177','1475665964739764226','1475774359513751553','1495596780596944898','1475460810832752642','1475457907124482049'],
      isoperatorAddType: false,
      addGoodsDisabled: false,
      notRequiredType: false,
      pageData: {
        goodsSkuVOList: {},
        goodsSpuVO: {
          goodsName: '',
          description: '',
          salePrice: '',
          costPrice: '',
          specName: '',
          sn: '',
          quantity: '',
          images: [],
          freightType: 1,
          commissionRatioLv1: '',
          commissionRatioLv2: '',
          isHasHelpSell: 1,
          categoryId: 0
        }
      },
      editPageData: {},
      userCategory: [],
      choiceClassifyData: {},
      routeData: {},
      quantityData: {
        type: 0,
        salePriceArr: [],
        costPriceArr: [],
        quantityAmount: 0
      },
      submitSpecArr: [],
      selectedSpecificType: false,
      getSpecType: true,
      editGoodsData: {},
      logisticsShow: false,
      freightType: 1, // 运费类型(1.全国包邮 2.无需物流)
      isHasHelpSell: true, // 是否开启帮卖
      commissionAmountLv1: '0.00', // 一级佣金预计
      commissionAmountLv2: '0.00', // 二级佣金预计
      commissionTipsType: false, // 佣金提示弹窗
      classifyPopupShow: false, // 分类选择弹窗
      categoryIndex: 0, // 分类选择ID
      shareData: {}, //分享数据
      addAccountId: '', // 运营者给其他用户添加商品的ID
      // dlAttendOfficial: false, // 关注公众号弹框变量
    }
  },
  computed: {
    userInfo () {
      return this.$store.state.userInfo
    },
    selectedLabel () {
      return this.$store.state.selectedLabel
    },
    selectedSpec () {
      return this.$store.state.selectedSpec
    },
    specificList () {
      return this.$store.state.specificList
    },
    goodsDetailsHtml () {
      return this.$store.state.editorObject.html || "" // 商品详情
    }
  },
  onLoad(r){
    this.routeData = r
    this.inItSpuFn()
    this.queryGetSystemCategoryFn()
    // 运营身份进入发布商品页面，获取上次运营操作的配置
    if (this.operatorIDArr.includes(this.userInfo.accountId)&&!this.routeData.spuId) {
      let operateData = uni.getStorageSync('operateData')
      this.isoperatorAddType = operateData.isoperatorAddType
      this.$nextTick(() => {
        this.addAccountId = operateData.addGooddsAccountId
      })
    }
  },
  onShow() {
    if (this.getSpecType) this.selectedSpecificType = false
    if (this.selectedSpec&&this.selectedSpec.length>0&&this.getSpecType) this.getSpecFn()
    this.getSpecType = true
  },
  methods: {
    setOperatorFn (e) {
      console.log(e)
      this.isoperatorAddType = e
    },
    choiceClassifyFn (index) {
      this.categoryIndex = index
    },
    defineClassifyFn () {
      this.classifyPopupShow = false
      this.choiceClassifyData = this.userCategory[this.categoryIndex]
    },
    // 获取系统默认分类
    queryGetSystemCategoryFn () {
      goodsApi.getSystemCategory().then(async (res_) => {
        if (res_.code == 200) {
          this.userCategory = res_.data
          if (this.routeData.spuId&&this.routeData.spuId>0) this.getGoodsFn(this.routeData.spuId)
        }
      })
    },
    //佣金计算方法
    commissionAmountFn () {
      let commissionRatioLv1 = (this.pageData.goodsSpuVO.commissionRatioLv1 || 0)/100 // 一级佣金比例
      let commissionRatioLv2 = (this.pageData.goodsSpuVO.commissionRatioLv2 || 50)/100 // 二级佣金比例
      if (this.specificList.goodsSpecValuesVOList&&this.specificList.goodsSpecValuesVOList.length>0) { // 规格设定了价格的计算
        if (this.quantityData.salePriceMin==this.quantityData.salePriceMax) {
          this.commissionAmountLv1 = (this.quantityData.salePriceMax*commissionRatioLv1).toFixed(2)
          this.commissionAmountLv2 = ((this.commissionAmountLv1 || 0)*commissionRatioLv2).toFixed(2)
        } else {
          let amountMinLv1 = this.quantityData.salePriceMin*commissionRatioLv1
          let amountMaxLv1 = this.quantityData.salePriceMax*commissionRatioLv1
          let amountMinLv2 = (amountMinLv1 || 0)*commissionRatioLv2
          let amountMaxLv2 = (amountMaxLv1 || 0)*commissionRatioLv2
          this.commissionAmountLv1 =  `${amountMinLv1.toFixed(2)}～${amountMaxLv1.toFixed(2)}`
          this.commissionAmountLv2 = `${amountMinLv2.toFixed(2)}～${amountMaxLv2.toFixed(2)}`
        }
      } else { // 规格没设置价格的计算
        this.commissionAmountLv1 = ((this.pageData.goodsSpuVO.salePrice || 0)*commissionRatioLv1).toFixed(2)
        this.commissionAmountLv2 = ((this.commissionAmountLv1 || 0)*commissionRatioLv2).toFixed(2)
      }
      console.log(this.commissionAmountLv1,this.commissionAmountLv2)
    },
    openFreightFn (type) { // type 1:点击选择物流方式 2:选择物流方式点击确定
      if(type==1) {
        this.logisticsShow = true
        this.freightType = this.pageData.goodsSpuVO.freightType
      }
      if(type==2) {
        this.logisticsShow = false
        this.pageData.goodsSpuVO.freightType = this.freightType
      }
    },
    setHelpSellFn (e) {
      this.pageData.goodsSpuVO.isHasHelpSell = e?1:0
    },
    logisticsCloseFn () {
      this.logisticsShow  = false
    },
    choiceFreightFn (type) {
      this.freightType = type
    },
    quantityInputFn (e) {
      this.$nextTick(() => {
        this.pageData.goodsSpuVO.quantity = Util.clearInteger(e.target.value)
      })
    },
    getGoodsFn (id) {
      goodsApi.getGoods({spuId: id}).then(async (res_) => {
        if (res_.code == 200) {
          let data = res_.data
          this.editGoodsData = {}
          this.editGoodsData = JSON.parse(JSON.stringify(data))
          this.pageData = {
            goodsSpuVO: {
              goodsName: data.goodsSpuRespVO.goodsName || '',
              description: data.goodsSpuRespVO.description || '',
              sn: data.goodsSpuRespVO.sn || '',
              marketPrice: Util.returnFloat(data.goodsSpuRespVO.marketPrice) || '',
              id: data.goodsSpuRespVO.id,
              images: JSON.parse(data.goodsSpuRespVO.images) || [],
              commissionRatioLv1: data.goodsSpuRespVO.commissionRatioLv1,
              commissionRatioLv2: data.goodsSpuRespVO.commissionRatioLv2,
              isHasHelpSell: data.goodsSpuRespVO.isHasHelpSell,
              freightType: data.goodsSpuRespVO.freightType
            }
          }
          this.$store.commit('SET_EDITOR_OBJECT', {html: data.goodsSpuRespVO.goodsDetailsPage}) // 商品详情回显

          this.isHasHelpSell = this.pageData.goodsSpuVO.isHasHelpSell==1?true:false
          if(data.goodsSpuRespVO.goodsLabelRespVOList&&data.goodsSpuRespVO.goodsLabelRespVOList.length>0) {
            let labelArr= JSON.parse(JSON.stringify(data.goodsSpuRespVO.goodsLabelRespVOList))
            this.$store.commit('CONTRAST_LABEL', labelArr)
            this.$store.commit('SELECTED_LABEL', data.goodsSpuRespVO.goodsLabelRespVOList)
          }
          if (data.goodsSpuRespVO.categoryId>0) {
            this.userCategory.forEach((item,i)=>{
              if (item.id==data.goodsSpuRespVO.categoryId) {
                this.categoryIndex = i
                this.choiceClassifyData = item
              }
            })
          }
          if (data.goodsSpecificationVOList.length<1) {
            this.pageData.goodsSpuVO = {
              ...this.pageData.goodsSpuVO,
              salePrice: data.goodsSkuRespVOList[0].salePrice>=0?Util.returnFloat(data.goodsSkuRespVOList[0].salePrice):'',
              costPrice: data.goodsSkuRespVOList[0].costPrice&&Util.returnFloat(data.goodsSkuRespVOList[0].costPrice)>0?Util.returnFloat(data.goodsSkuRespVOList[0].costPrice) : '',
              specName: data.goodsSpecificationVOList.length>0?data.goodsSkuRespVOList[0].specName:''
            }
            if (data.goodsSkuRespVOList[0].quantity) {
              this.pageData.goodsSpuVO = {
                ...this.pageData.goodsSpuVO,
                quantity: data.goodsSkuRespVOList[0].quantity == '99999999'?'':data.goodsSkuRespVOList[0].quantity
              }
            } else {
              this.pageData.goodsSpuVO = {
                ...this.pageData.goodsSpuVO,
                quantity: ''
              }
            }
          } else {
            let goodsSpecArr = data.goodsSkuRespVOList
            let specificList = {
              specName: data.goodsSkuRespVOList[0].specName,
              goodsSpecValuesVOList: []
            }
            goodsSpecArr.forEach((item,i)=>{
              let itemData = {...item}
              if (itemData.quantity == '99999999') {
                itemData= {
                  ...itemData,
                  quantity: ''
                }
              }
              specificList.goodsSpecValuesVOList.push(itemData)
            })
            this.$store.commit('SPECIFIC_LIST', specificList)
            let modifyData = JSON.parse(JSON.stringify(specificList))
            this.$store.commit('MODIFY_SPECIFIC_LIST', modifyData)
            let goodsSpecificationVOData = JSON.parse(JSON.stringify(data.goodsSpecificationVOList))
            this.$store.commit('MODIFY_SELECTED_SPEC', goodsSpecificationVOData)
            this.$store.commit('SELECTED_SPEC', data.goodsSpecificationVOList)
            this.getSpecFn()
          }
          this.commissionAmountFn()
          this.$nextTick(() => {
            this.$store.commit('OPERATE_SPEC_TYPE_STR', '')
            if (this.routeData.spuId&&this.routeData.spuId>0) this.addGoodsFn(2) // 用发布方法来组装好编辑商品之前的数据用于对比
          })
          this.notRequiredType = true
        }
      })
    },
    maxLengthInputFn (e, name, mun) {
      if (e.detail.value.length > mun) {
        this.$nextTick(() => {
          this.pageData.goodsSpuVO = {
            ...this.pageData.goodsSpuVO,
            [name]: e.detail.value.slice(0, mun)
          }
        })
      }
    },
    inputFn (e, name) {
      let inputValue = Util.clearNoNum(e.target.value)
      this.$nextTick(() => {
        this.pageData.goodsSpuVO = {
          ...this.pageData.goodsSpuVO,
          [name]: inputValue
        }
        if (['salePrice','commissionRatioLv1','commissionRatioLv2'].includes(name)) this.commissionAmountFn()
      })
    },
    blurFn (e, name) {
      let inputValue = Util.clearNoNum(e.target.value)
      if (['commissionRatioLv1','commissionRatioLv2'].includes(name)) {
        if (inputValue>80&&name=='commissionRatioLv1') {
          wx.showToast({
            icon: 'none',
            mask: true,
            title: '帮卖佣金不可大于80%！'
          })
          inputValue = 80
        }
        if (inputValue<0.1&&name=='commissionRatioLv1') {
          wx.showToast({
            icon: 'none',
            mask: true,
            title: '帮卖佣金不可小于0.1%！'
          })
          inputValue = 0.1
        }
        if (inputValue>100&&name=='commissionRatioLv2') {
          wx.showToast({
            icon: 'none',
            mask: true,
            title: '二级佣金不可大于100%！'
          })
          inputValue = 100
        }
      }
      this.$nextTick(() => {
        this.pageData.goodsSpuVO = {
          ...this.pageData.goodsSpuVO,
          [name]: inputValue
        }
        if (['commissionRatioLv1','commissionRatioLv2'].includes(name)) this.commissionAmountFn()
      })
    },
    getSpecFn () {
      let specData = []
      if (this.routeData.spuId) {
        specData = JSON.parse(JSON.stringify(this.$store.state.selectedSpec))
      }
      let idDataJosn = []
      let specificList = this.$store.state.specificList
      this.notRequiredType = true
      this.selectedSpecificType = true
      this.submitSpecArr = []
      this.quantityData = {
        type: 0,
        salePriceArr: [],
        costPriceArr: [],
        quantityAmount: 0
      }
      // console.log(specificList,specData,'specificListspecificLists99999999999999999pecificListspecificList___')
      let specNameArr = specificList.specName&&specificList.specName.split('^^')
      if (specificList.goodsSpecValuesVOList&&specificList.goodsSpecValuesVOList.length>0) {
        specificList.goodsSpecValuesVOList.forEach((item,i)=>{
          this.quantityData = {
            ...this.quantityData,
            quantityAmount: item.quantity&&item.quantity>0&&item.quantity!='99999999'?Number(this.quantityData.quantityAmount)+Number(item.quantity):this.quantityData.quantityAmount
          }
          this.quantityData.salePriceArr.push(item.salePrice)
          this.quantityData.costPriceArr.push(item.costPrice?item.costPrice:'')
          if (item.quantity=='' || item.quantity=='99999999') {
            this.quantityData = {
            ...this.quantityData,
              type: 1
            }
          }
          let specValueArr = item.specValue.split('^^')
          let submitData = {
            costPrice: item.costPrice || '',
            salePrice: item.salePrice,
            quantity: item.quantity || '',
            images: item.images&&item.images.url?JSON.stringify(item.images):item.images,
            goodsSpecReqVO: []
          }
          if (this.routeData.spuId) {
            submitData = {
              ...submitData,
              goodsName:  item.goodsName,
              id: item.id,
              sn: item.sn,
              spuId: item.spuId,
            }
          }
          this.submitSpecArr.push(submitData)
          if (this.routeData.spuId&&this.$store.state.selectedSpec.length>0) {
            specNameArr.forEach((specName,j)=>{
              let data_ = {
                specName: specName,
                goodsAddSpecValueVOList: []
              }
              if (this.routeData.spuId&&(this.$store.state.operateSpecTypeStr=='已修改'||this.$store.state.operateSpecTypeStr=='')) {
                data_ = {
                  ...data_,
                  id: specData[j].id,
                }
              }
              this.submitSpecArr[i].goodsSpecReqVO.push(data_)
            })
          } else {
            specNameArr.forEach((specName,j)=>{
              this.submitSpecArr[i].goodsSpecReqVO.push({
                specName: specName,
                goodsAddSpecValueVOList: []
              })
            })
          }
          // console.log(this.submitSpecArr,'this.submitSpecArr',specValueArr,'specValueArr')
          this.submitSpecArr[i].goodsSpecReqVO.forEach((goods,k)=>{
            specValueArr.forEach((specValue,r)=>{
              if (k==r) {
                let specValueStr = specValue
                this.submitSpecArr[i].goodsSpecReqVO[k].goodsAddSpecValueVOList.push({
                  specValue: specValueStr
                })
              }
            })
          })
        })
      }
      specData.forEach((specA, u)=>{
        specA.goodsSpecValuesVOList.forEach((specB,m)=>{
          idDataJosn.push(specB)
        })
      })
      if (this.routeData.spuId&&(this.$store.state.operateSpecTypeStr=='已修改'||this.$store.state.operateSpecTypeStr=='')) {
        let submitSpecArrParse = JSON.parse(JSON.stringify(this.submitSpecArr))
        submitSpecArrParse.forEach((subSpec,spIndex)=>{
          subSpec.goodsSpecReqVO.forEach((goodData,goodIndex)=>{
            idDataJosn.forEach((idData,idIndex)=>{
              if (goodData.goodsAddSpecValueVOList[0].specValue == idData.specValue) {
                let data = {
                  specValue: goodData.goodsAddSpecValueVOList[0].specValue,
                  id: idData.id
                }
                this.submitSpecArr[spIndex].goodsSpecReqVO[goodIndex].goodsAddSpecValueVOList[0] = data
              }
            })
          })
        })
      }
      this.quantityData = {
        ...this.quantityData,
        salePriceMax: Util.getMaximin(this.quantityData.salePriceArr,'max'),
        salePriceMin: Util.getMaximin(this.quantityData.salePriceArr,'min'),
        costPriceMax: Util.getMaximin(this.quantityData.costPriceArr,'max'),
        costPriceMin: Util.getMaximin(this.quantityData.costPriceArr,'min'),
      }
      if (this.routeData.spuId&&this.$store.state.contrastSpecArr.length<1) {
        this.$store.commit('CONTRAST_SPEC_ARR', this.submitSpecArr)
      }
      this.commissionAmountFn()
      console.log(this.submitSpecArr,this.$store.state.contrastSpecArr,'00_________00')
    },
    addlabelFn () {
      this.navigateTo({ url: '/pagesA/libraryGoods/labelList?spuId='+this.routeData.spuId })
    },
    addSpecsFn () {
      let url = '/pagesA/libraryGoods/goodsSpecs?spuId='+this.routeData.spuId
      if (this.pageData.goodsSpuVO.specName&&this.$store.state.selectedSpec.length<1) {
        let arr = this.$store.state.selectedSpec
        arr.push({
          specName: '默认规格',
          goodsSpecValuesVOList: [
            {specValue: this.pageData.goodsSpuVO.specName}
          ]
        })
        url = '/pagesA/libraryGoods/goodsSpecs?specNameType=1&spuId='+this.routeData.spuId
        this.$store.commit('SELECTED_SPEC', arr)
      }
      this.navigateTo({ url: url })
    },
    async uploadImgFn () {
      let _this = this
      _this.getSpecType = false
      const res = await upload({ type: 'image', number: 9, checkSize: false, maxLength:9, transmittedLength: this.pageData.goodsSpuVO.images.length }, _this)
      if (res.status == 'success') {
        if (this.pageData.goodsSpuVO.images.length<1) {
          this.pageData.goodsSpuVO.images=[...res.data]
        } else {
          this.pageData.goodsSpuVO.images = this.pageData.goodsSpuVO.images.concat(res.data)
        }
        console.log(this.pageData.goodsSpuVO.images)
      } else {
        return wx.showToast({
          icon: 'none',
          mask: true,
          title: res.msg || '上传失败，请重试！'
        })
      }
    },
    closeFn (index) {
      this.pageData.goodsSpuVO.images.splice(index, 1)
    },
    // 分享图片回调
    _shareSuccess(e){
      this.shareData = {
        ...this.shareData,
        ...e,
        isShare: true, // true去列表页面就弹出提示框，到列表页面之后改成false
      }
      this.$store.commit('GOODS_SHARE_DATA', this.shareData)
      // 绘图成功跳转页面
      this.addGoodsDisabled = false
      this.navigateBack({
        delta: 1
      })
    },
    // 发布成功邀请帮卖
    _openShareHelpProfit(data){
      let goodsData = data
      this.shareData = { // 把shopWindowId存在分享数据里面
        ...this.shareData,
        shopWindowId: goodsData.shopWindowId,
        title: goodsData.title
      }
      const canvasData = {
        isGoods: true,
        userAvatar: this.userInfo.communityLogo,// 团长头像
        userNickname: this.userInfo.communityName,// 名字
        bgImgUrl: goodsData.url,// 背景图片
        btnText: '帮卖立赚',
        type: 2,
        followGroupNumber: '一大波人赶来中'
      }
      this.$nextTick(()=>{
        this.$refs.shareChild.shareFrends(canvasData) // 绘制分享小图片
      })
    },
    inItSpuFn() {
      this.$store.commit('SELECTED_SPEC', [])
      this.$store.commit('SYSTEM_SPEC_LIST', [])
      this.$store.commit('SPECIFIC_LIST', [])
      this.$store.commit('SELECTED_LABEL', [])
    },
    addGoodsFn (type) {
      let params = JSON.parse(JSON.stringify(Util.removeEmptyField(this.pageData)))
      if (!params.goodsSpuVO.goodsName) {
        return wx.showToast({
          icon: 'none',
          mask: true,
          title: '请添加商品名称!'
        })
      }
      // console.log(this.specificList.goodsSpecValuesVOList,'___________',this.submitSpecArr)
      // this.submitSpecArr.length<1
      if (!this.specificList.goodsSpecValuesVOList || this.specificList.goodsSpecValuesVOList.length<1) {
        // &&!this.selectedSpecificType&&type!=2
        if (!params.goodsSpuVO.salePrice) {
          return wx.showToast({
            icon: 'none',
            mask: true,
            title: '请添加商品价格!'
          })
        }
        if (Number(params.goodsSpuVO.salePrice)<0.01) {
          return wx.showToast({
            icon: 'none',
            mask: true,
            title: '商品价格不可小于0.01元!'
          })
        }
      }
      if (!params.goodsSpuVO.images||params.goodsSpuVO.images.length<1) {
        return wx.showToast({
          icon: 'none',
          mask: true,
          title: '请添加商品图片！'
        })
      }
      if (params.goodsSpuVO.isHasHelpSell==1) { // 已开启帮卖 未填写值添加默认值
        if(!params.goodsSpuVO.commissionRatioLv1){
          return wx.showToast({
            icon: 'none',
            mask: true,
            title: '请填写帮卖佣金比例！'
          })
          // this.pageData.goodsSpuVO.commissionRatioLv1 = 30
          // this.commissionAmountFn()
          // params.goodsSpuVO.commissionRatioLv1 = this.pageData.goodsSpuVO.commissionRatioLv1
        }
        if(!params.goodsSpuVO.commissionRatioLv2)
        this.pageData.goodsSpuVO.commissionRatioLv2 = 50
        this.commissionAmountFn()
        params.goodsSpuVO.commissionRatioLv2 = this.pageData.goodsSpuVO.commissionRatioLv2
      }

      if (params.goodsSpuVO.images.length>0) {
        params.goodsSpuVO.images.forEach((item)=>{
          item.tempFilePath = ''
        })
      }
      if (this.selectedLabel.length>0) {
        let idArr = []
        let nameArr = []
        this.selectedLabel.forEach((item)=>{
          idArr.push(item.id)
          nameArr.push(item.name)
        })
        params.goodsSpuVO = {
          ...params.goodsSpuVO,
          labelId: idArr,
          labelName: nameArr
        }
      }
      params.goodsSpuVO = {
        ...params.goodsSpuVO,
        images: JSON.stringify(params.goodsSpuVO.images) || '',
        categoryId: this.choiceClassifyData.id || 0
      }
      if (this.selectedSpecificType) {
        params.goodsSpuVO = {
          ...params.goodsSpuVO,
          salePrice: '',
          costPrice: '',
          quantity: '',
        }
        if (type==0) {
          params = {
            ...params,
            goodsSkuVOList: this.submitSpecArr
          }
        }
        if (type==1||type==2) {
          params = {
            ...params,
            goodsUpdateSkuVOList: this.submitSpecArr,
          }
        }
      }
      if (type == 2) {
        this.editPageData = {}
        this.editPageData = JSON.parse(JSON.stringify(params))
        return
      }
      if (type == 0) {
        params.goodsSpuVO.goodsDetailsPage = this.goodsDetailsHtml
        console.log(params,'新增参数');

        wx.showLoading({
          title: '添加中',
          mask: true
        })
        if (this.operatorIDArr.includes(this.userInfo.accountId)&&this.isoperatorAddType) { //运营身份进来
          if (!this.addAccountId) {
            return wx.showToast({
              icon: 'none',
              mask: true,
              title: '请添加用户ID！'
            })
          }
          console.log(params,'运营者添加')
          params = {
            ...params,
            accountId: this.addAccountId
          }
          goodsApi.addOperatorsGoods(params).then(async (res_) => {
            if (res_.code == 200) {
              wx.hideLoading()
              wx.showToast({
                icon: 'none',
                mask: true,
                duration: 2000,
                title: `给【${this.addAccountId}】添加商品成功!`
              })
              let operateData = {
                addGooddsAccountId: this.addAccountId,
                isoperatorAddType: this.isoperatorAddType
              }
              uni.setStorageSync("operateData", operateData) // 存下运营的数据方便回调
              setTimeout(()=>{
                this.addGoodsDisabled = false
                this.navigateBack({
                  delta: 1
                })
              },1000)
            }
          })
        } else {
          goodsApi.addGoods(params).then(async (res_) => {
            if (res_.code == 200) {
              wx.hideLoading()
              wx.showToast({
                icon: 'none',
                mask: true,
                title: '添加成功!'
              })
              uni.setStorageSync("operateData", {addGooddsAccountId: '',isoperatorAddType: false}) // 运营身份发布自己的商品初始化下配置的数据
              if (this.isHasHelpSell) { // 开启帮卖走绘制分享逻辑
                let canvasData = {
                  url: this.pageData.goodsSpuVO.images[0].url,
                  shopWindowId: res_.data,
                  title: this.pageData.goodsSpuVO.goodsName
                }
                this._openShareHelpProfit(canvasData)
              } else {
                setTimeout(()=>{
                  this.addGoodsDisabled = false
                  this.navigateBack({
                    delta: 1
                  })
                },1000)
              }
            } else {
              this.addGoodsDisabled = false
              wx.hideLoading()
            }
          })
        }
      }
      if (type == 1) {
        let diversityData = {}
        let specsListArr = []
        let modifyParams = {}
        let modifySpecArr = []
        if (JSON.stringify(this.editPageData)==JSON.stringify(params) && this.editGoodsData.goodsSpuRespVO.goodsDetailsPage == this.goodsDetailsHtml) { // 没修改直接返回上一页
          this.navigateBack({
            delta: 1
          })
          return
        } else {
          console.log(this.editPageData,params,'999999999999999999999999999999')
          if (this.editPageData.goodsSpuVO.images != params.goodsSpuVO.images) {
            diversityData={
              ...diversityData,
              images: params.goodsSpuVO.images
            }
          }
          if (this.editPageData.goodsSpuVO.commissionRatioLv1 != params.goodsSpuVO.commissionRatioLv1) {
            diversityData={
              ...diversityData,
              commissionRatioLv1: params.goodsSpuVO.commissionRatioLv1
            }
          }
          if (this.editPageData.goodsSpuVO.commissionRatioLv2 != params.goodsSpuVO.commissionRatioLv2) {
            diversityData={
              ...diversityData,
              commissionRatioLv2: params.goodsSpuVO.commissionRatioLv2
            }
          }
          if (this.editPageData.goodsSpuVO.freightType != params.goodsSpuVO.freightType) {
            diversityData={
              ...diversityData,
              freightType: params.goodsSpuVO.freightType
            }
          }
          if (this.editPageData.goodsSpuVO.goodsName != params.goodsSpuVO.goodsName) {
            diversityData={
              ...diversityData,
              goodsName: params.goodsSpuVO.goodsName
            }
          }
          if (this.editPageData.goodsSpuVO.description != params.goodsSpuVO.description) {
            diversityData={
              ...diversityData,
              description: params.goodsSpuVO.description || ' ', // 因为提交数据需要过滤掉''，null ，加个' '，防止提交过滤掉，在提交前在还原为‘’
            }
          }
          if (this.editPageData.goodsSpuVO.marketPrice != params.goodsSpuVO.marketPrice) {
            diversityData={
              ...diversityData,
              marketPrice: params.goodsSpuVO.marketPrice || 0
            }
          }
          if (this.editPageData.goodsSpuVO.salePrice != params.goodsSpuVO.salePrice) {
            diversityData={
              ...diversityData,
              salePrice: params.goodsSpuVO.salePrice
            }
          }
          if (this.editPageData.goodsSpuVO.costPrice != params.goodsSpuVO.costPrice) {
            diversityData={
              ...diversityData,
              costPrice: params.goodsSpuVO.costPrice || 0
            }
          }
          if (this.editPageData.goodsSpuVO.categoryId != params.goodsSpuVO.categoryId) {
            diversityData={
              ...diversityData,
              categoryId: params.goodsSpuVO.categoryId
            }
          }
          if (!this.$store.state.selectedSpec||this.$store.state.selectedSpec.length<1) {
            if (this.editPageData.goodsSpuVO.quantity != params.goodsSpuVO.quantity) {
              diversityData={
                ...diversityData,
                quantity: params.goodsSpuVO.quantity
                // quantity: params.goodsSpuVO.quantity>0&&params.goodsSpuVO.quantity!="99999999"?Number(params.goodsSpuVO.quantity):'99999999'
              }
            }
          }
          if (params.goodsSpuVO.specName&&this.editGoodsData.goodsSpecificationVOList.length>0) {
            if (this.editPageData.goodsSpuVO.specName != params.goodsSpuVO.specName) {
              specsListArr[0] = {
                ...specsListArr[0],
                spuId: params.goodsSpuVO.id,
                skuId: this.editGoodsData.goodsSkuRespVOList[0].id,
                specName: params.goodsSpuVO.specName
              }
            }
            if (this.editPageData.goodsSpuVO.quantity != params.goodsSpuVO.quantity) {
              specsListArr[0] = {
                ...specsListArr[0],
                spuId: params.goodsSpuVO.id,
                skuId: this.editGoodsData.goodsSkuRespVOList[0].id,
                quantity: params.goodsSpuVO.quantity
              }
            }
          }
          let operateData = this.$store.state.operateLabel
          if (operateData.addArr&&operateData.addArr.length>0) {
            modifyParams = {
              ...modifyParams,
              addGoodsLabelVOList: operateData.addArr
            }
          }
          if (operateData.deleteArr&&operateData.deleteArr.length>0) {
            modifyParams = {
              ...modifyParams,
              deleteGoodsLabelVOList: operateData.deleteArr
            }
          }
          console.log(this.$store.state.operateSpecData,this.$store.state.operateSpecTypeStr)
          // return
          if (this.$store.state.operateSpecTypeStr == '已修改') {
            let contrastSpecArr = this.$store.state.contrastSpecArr
            let gatherData = {}
            console.log(this.submitSpecArr, contrastSpecArr, '已修改已修改已修改')
            this.submitSpecArr.forEach((subItem,subIndex)=>{
              gatherData = {}
              if (Number(subItem.costPrice)!=Number(contrastSpecArr[subIndex].costPrice)) {
                gatherData = {
                  ...gatherData,
                  costPrice: subItem.costPrice
                }
              }
              if (Number(subItem.salePrice)!=Number(contrastSpecArr[subIndex].salePrice)) {
                gatherData = {
                  ...gatherData,
                  salePrice: subItem.salePrice
                }
              }
              if (subItem.images!=contrastSpecArr[subIndex].images) {
                let imgData = ''
                if (subItem.images&&typeof(subItem.images) == 'object') {
                  imgData = JSON.stringify(subItem.images)
                } else {
                  imgData = subItem.images
                }
                gatherData = {
                  ...gatherData,
                  images: imgData
                }
              }
              if (subItem.quantity!=contrastSpecArr[subIndex].quantity) {
                gatherData = {
                  ...gatherData,
                  quantity: subItem.quantity
                }
              }
              let specArrVo = []
              subItem.goodsSpecReqVO.forEach((gdSp,gdSpIndex)=>{
                specArrVo.push({
                  specName: gdSp.specName,
                  id: gdSp.id,
                  goodsUpdateSpecValueVOList: gdSp.goodsAddSpecValueVOList
                })
              })
              gatherData = {
                ...gatherData,
                skuId: subItem.id,
                goodsUpdateSpecReqVOList: specArrVo
              }
              modifySpecArr.push(gatherData)
            })
            console.log(modifySpecArr,'-----------------modifySpecArr-----------------')
          }
          if (this.$store.state.operateSpecTypeStr == '已新增' || this.$store.state.operateSpecTypeStr == '已修改') {
            let operateSpecDataArr = this.$store.state.operateSpecData
            let goodsDeleteSkuData = {
              skuIds: [],
              specIds: [],
              specValuesIds: []
            }
            if (operateSpecDataArr.deleteBigArr.length>0) { // 删除大规格项逻辑
              operateSpecDataArr.deleteBigArr.forEach((op,u)=>{
                goodsDeleteSkuData.specIds.push(op.id)
              })
              if (operateSpecDataArr.deleteBigArr[0].skuIdArr.length>0) {
                modifyParams = {
                  ...modifyParams,
                  goodsDeleteSkuVO: {
                    skuIds: operateSpecDataArr.deleteBigArr[0].skuIdArr,
                    specIds: goodsDeleteSkuData.specIds
                  }
                }
              }
            }
            if (operateSpecDataArr.deleteSmallArr.length>0) { // 删除小规格项逻辑
              let deleteSmallArr = operateSpecDataArr.deleteSmallArr
              let specValuesIdArr = []
              let skuIdArr = []
              deleteSmallArr.forEach((item,i)=>{
                specValuesIdArr.push(item.id),
                skuIdArr.push(item.skuId)
              })
              modifyParams = {
                ...modifyParams,
                goodsDeleteSkuVO: {
                  skuIds: skuIdArr,
                  specValuesIds: specValuesIdArr
                }
              }
            }
          }
        }
        diversityData = {
          ...diversityData,
          isHasHelpSell: params.goodsSpuVO.isHasHelpSell,
        }
        modifyParams = {
          ...modifyParams,
          goodsSpuVO: diversityData,
          goodsUpdateSkuVOList: []
        }
        if (specsListArr.length>0) {
          modifyParams.goodsUpdateSkuVOList = modifyParams.goodsUpdateSkuVOList.concat(specsListArr)
        }
        console.log(this.$store.state.operateSpecTypeStr,'编辑状态编辑状态编辑状态')
        if (this.$store.state.operateSpecTypeStr == '已修改') {
          modifyParams = {
            ...modifyParams,
            goodsUpdateSkuVOList: modifySpecArr
          }
          let addSpecValueVO = []
          params.goodsUpdateSkuVOList.forEach((pg,w)=>{
            if (pg.goodsSpecReqVO.length==1) {
              if (!pg.goodsSpecReqVO[0].goodsAddSpecValueVOList[0].id) {
                addSpecValueVO.push(pg)
              }
            }
          })
          modifyParams = {
            ...modifyParams,
            goodsAddSkuVOList:addSpecValueVO
          }
          console.log(addSpecValueVO,'1--------------1')
        }
        if (this.$store.state.operateSpecTypeStr=='已新增'&&params.goodsUpdateSkuVOList&&params.goodsUpdateSkuVOList.length>0) {
          modifyParams = {
            ...modifyParams,
            goodsAddSkuVOList:params.goodsUpdateSkuVOList
          }
        }
        modifyParams.goodsSpuVO = {
          ...modifyParams.goodsSpuVO,
          spuId: params.goodsSpuVO.id
        }
        console.log(this.editGoodsData,params.goodsSpuVO,this.$store.state.specificList,'oooooooooooooooo')
        if (this.editGoodsData.goodsSpecificationVOList.length<1) {
          if (params.goodsSpuVO.specName || this.$store.state.specificList.specName) {
            let goodsDeleteSkuData = {
              skuIds: [],
              specIds: [],
              specValuesIds: []
            }
            this.editGoodsData.goodsSkuRespVOList.forEach((edItem, edIndex)=>{
              goodsDeleteSkuData.skuIds.push(edItem.id)
              // goodsDeleteSkuData.specValuesIds.push(edItem.spuId)
            })
            modifyParams = {
              ...modifyParams,
              goodsDeleteSkuVO: {
                skuIds: goodsDeleteSkuData.skuIds,
                // specValuesIds: goodsDeleteSkuData.specValuesIds
              }
            }
            if (this.selectedSpec.length<1) {
              let addGoodsAddSkuVOList = []
              let data = {
                goodsSpecReqVO: []
              }
              if (params.goodsSpuVO.salePrice>0) {
                data = {
                  ...data,
                  salePrice: params.goodsSpuVO.salePrice
                }
              }
              if (params.goodsSpuVO.costPrice>0) {
                data = {
                  ...data,
                  costPrice: params.goodsSpuVO.costPrice
                }
              }
              addGoodsAddSkuVOList.push(data)
              data.goodsSpecReqVO.push({
                specName: '默认规格',
                goodsAddSpecValueVOList: []
              })
              data.goodsSpecReqVO[0].goodsAddSpecValueVOList.push({
                specValue: params.goodsSpuVO.specName
              })
              modifyParams = {
                ...modifyParams,
                goodsAddSkuVOList: addGoodsAddSkuVOList
              }
            }
          }
        }
        params.goodsSpuVO = {
          ...params.goodsSpuVO,
          spuId: params.goodsSpuVO.id
        }
        modifyParams = Util.removeEmptyField(modifyParams)
        if (typeof(modifyParams.goodsSpuVO.images) == 'object') {
          modifyParams.goodsSpuVO = {
            ...modifyParams.goodsSpuVO,
            images: JSON.stringify(modifyParams.goodsSpuVO.images)
          }
        }
        if (modifyParams.goodsUpdateSkuVOList&&modifyParams.goodsUpdateSkuVOList.length>0) {
          modifyParams.goodsUpdateSkuVOList.forEach((gdItem, gdi)=>{
            if (typeof(gdItem.images) == 'object') {
              gdItem.images = JSON.stringify(gdItem.images)
            }
          })
        }
        modifyParams.goodsSpuVO.goodsDetailsPage = this.goodsDetailsHtml
        if (modifyParams.goodsSpuVO.description == ' ') { // 因为提交数据需要过滤掉''，null等还原描述字段为空
          modifyParams.goodsSpuVO = {
            ...modifyParams.goodsSpuVO,
            description: ''
          }
        }
        console.log(modifyParams,'编辑参数');

        wx.showLoading({
          title: '保存中',
          mask: true
        })
        goodsApi.updateGoods(modifyParams).then(async (res_) => {
          if (res_.code == 200) {
            wx.hideLoading()
            wx.showToast({
              icon: 'none',
              mask: true,
              title: '编辑成功!'
            })
            // 初始化数据
            this.$store.commit('OPERATE_SPEC_DATA', {deleteBigArr: [],deleteSmallArr: []})
            this.$store.commit('OPERATE_SPEC_TYPE_STR', '')
            this.$store.commit('CONTRAST_SPEC_ARR', '')
            this.inItSpuFn()// 初始化数据
            if (this.isHasHelpSell) { // 开启帮卖走绘制分享逻辑
              let canvasData = {
                url: this.pageData.goodsSpuVO.images[0].url,
                shopWindowId: res_.data,
                title: this.pageData.goodsSpuVO.goodsName
              }
              this._openShareHelpProfit(canvasData)
            } else {
              setTimeout(()=>{
                this.addGoodsDisabled = false
                this.navigateBack({
                  delta: 1
                })
                // this.navigateTo({ url: '/pagesA/libraryGoods/libraryGoods' })
              },1000)
            }
          } else {
            wx.hideLoading()
            this.addGoodsDisabled = false
          }
        })
      }
      this.addGoodsDisabled = false
    },
    // 去编辑商品详情
    _goEditGoods(){
      if(this.routeData.spuId){
        this.navigateTo({url: `/pagesB/goods/goodsEdit?spuId=${this.routeData.spuId}`})
      }else{
        this.navigateTo({url: '/pagesB/goods/goodsEdit'})
      }
    }
  },
  filters: {
    numFilter (value) {
      // 截取当前数据到小数点后两位
      let realVal = value.toFixed(2)
      return realVal
    }
  },
  onUnload(){
    console.log('清除商品详情缓存');
    this.$store.commit('SET_EDITOR_OBJECT', {})
  }
}
</script>

<style lang="scss" scoped>
.addProduct_layout {
  width: 100%;
  height: calc(100% - 100rpx);
}
.addProduct_msg_box {
  width: 100%;
  height: 100%;
  background: #f2f3f5;
  .upload_img_box {
    background-color: #fff;
    padding: 32rpx;
    .upload_img_ul {
      display: flex;
      flex-wrap: wrap;
      .upload_img_li {
        width: 120rpx;
        height: 120rpx;
        opacity: 1;
        background: #f9f9f9;
        margin-right: 20rpx;
        margin-bottom: 20rpx;
        position: relative;
        border-radius: 8rpx;
        overflow: hidden;
        &.upload_img_li_k {
          width: 120rpx;
          height: 2rpx;
          opacity: 0;
        }
        &:nth-child(5n) {
          margin-right: 0;
        }
        .img_box {
          display: block;
          width: 100%;
          height: 100%;
        }
        .cover_tab_box {
          display: inline-block;
          position: absolute;
          left: 0;
          top: 0;
          font-size: 24rpx;
          color: #fff;
          padding: 0rpx 4rpx;
          background: rgba(50, 50, 51, 0.5);
        }
        .close_icon_box {
          position: absolute;
          right: 0px;
          top: 0px;
          padding: 4rpx;
          img {
            width: 28rpx;
            height: 28rpx;
            display: block;
          }
        }
        &.upload_img_li_btn {
          display: flex;
          justify-content: center;
          align-items: center;
          .iconfont_fill2 {
            color: #DCDEE0;
          }
          img {
            width: 64rpx;
            height: 64rpx;
          }
        }
        // &:nth-child(3n) {
        //   margin-right: 0rpx;
        // }
      }
    }
  }
  .goods_msg_con {
    border-top: 1px solid #eee;
    background-color: #fff;
    width: 100%;
    margin-bottom: 20rpx;
    &.goods_msg_con_two {
      margin-top: 20rpx;
      margin-bottom: 0;
      .goods_msg_box {
        .goods_msg_left {
          width: 340rpx;
          color: #323233;
        }
        .goods_msg_right {
          // width: 300rpx;
          color: #B2B2B2;
          margin-left: 4rpx;
          display: flex;
          align-items: center;
          .arrow_box{
            color: #C8C9CC;
          }
          .notRequired_img_b {
             transform: rotate(90deg);
          }
          .notRequired_img_t {
            transform: rotate(0deg);
          }
        }
      }
    }
    &.goods_msg_con_not {
      .goods_msg_box {
        .goods_msg_left {
          width: 160rpx;
          margin-right: 14rpx;
        }
        .goods_msg_right {
          // width: 460rpx;
          display: flex;
          align-items: center;
          .arrow_box{
            color: #C8C9CC;
          }
        }
        .goods_msg_right_textR {
          .input_box {
            text-align: right;
          }
          .addSpecs_box {
            display: flex;
            align-items: center;
          }
        }
      }
      .goods_msg_box_f {
        display: flex;
        justify-content: space-between;
        .goods_msg_right {
          display: flex;
          align-items: center;
          color: #C8C9CC;
          .arrow_box{
            color: #C8C9CC;
          }
        }
      }
    }
    .goods_msg_box {
      display: flex;
      align-items: center;
      padding: 24rpx 32rpx;
      color: #000;
      &.goods_msg_box_start {
        width: 100%;
        align-items: flex-start;
      }
      &.goods_msg_box_r {
        justify-content: space-between;
        .goods_msg_right {
          display: flex;
          align-items: center;
          justify-content: flex-end;
          line-height: 40rpx;
          .arrow_box{
            color: #C8C9CC;
            margin-left: 10rpx;
          }
          img {
            width: 32rpx;
            height: 32rpx;
          }
        }
      }
      .goods_msg_left {
        display: flex;
        width: 180rpx;
        align-items: center;
        font-weight: bolder;
        line-height: 48rpx;
        flex: 0 0 auto;
        em {
          font-size: 20rpx;
        }
        i {
          color: #E44435;
        }
      }
      .goods_msg_right {
        .choiceClassify_box {
          color: rgba(0,0,0,0.90);
        }
        .selected_label_box {
          display: flex;
          flex-wrap: wrap;
          justify-content: center;
          align-items: center;
          li {
            padding: 8rpx 24rpx;
            border-radius: 4rpx;
            font-size: 24rpx;
            background-color: #ffe5de;
            color: #E44435;
            font-weight: 400;
            position: relative;
            margin-left: 16rpx;
          }
        }
        &.goods_msg_right_btn {
          width: 526rpx;
          display: flex;
          justify-content: space-between;
          align-items: center;
        }
        &.goods_msg_right_w {
          width: 300rpx;
        }
        .input_box {
          width: 440rpx;
          height: 48rpx;
          color: rgba(0,0,0,0.90);
          &.input_box_z {
            width: 300rpx;
          }
        }
        .goods_msg_redBtn {
          display: flex;
          width: 160rpx;
          flex: 0 0 auto;
          justify-content: center;
          align-items: center;
          color: #E44435;
          font-size: 32rpx;
          font-weight: 400;
        }
        .opt_spec_list {
          //width: 320rpx;
          .opt_spec_li {
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            font-weight: 24rpx;
            i {
              display: flex;
              align-items: center;
              justify-content: center;
              &:last-child {
                em {
                  opacity: 0;
                }
              }
            }
          }
        }
        .salePrice_box {
          color: #E44435;
          display: flex;
          align-items: center;
        }
        .costPrice_box {
          color: #C8C9CC;
          display: flex;
          align-items: center;
        }
        .quantity_box {
          display: flex;
          align-items: center;
          color: #C8C9CC;
        }
      }
      .textarea_wrap {
        width: calc(100% - 180rpx);
        padding: 8rpx 8rpx 8rpx 0;
      }
      .textarea_box {
        width: 100%;
        min-height: 48rpx;
        font-size: 28rpx;
        line-height: normal;
        font-weight: 400;
        //overflow: hidden;
        //padding: 8rpx 8rpx 8rpx 0;
        &.description_box {
          padding: 16rpx;
          min-height: 192rpx;
          background: #F7F8FA;
          border-radius: 8rpx;

        }
      }
    }
  }
}

.fixed_box {
  z-index: 98;
}
.popup_content_box {
  .popup_content_msg {
    height: 524rpx;
    padding-bottom: 80rpx;
  }
  .classify_box {
    padding-bottom: 0;
    .classify_ul_box {
        height: 40vh;
       .classify_li_box {
        padding: 24rpx 32rpx;
        display: flex;
        justify-content: space-between;
        .classify_li_l {
          font-size: 28rpx;
          line-height: 40rpx;
          color: #323233;
        }
        .classify_li_r {
          padding: 4rpx;
          .img_box {
            width: 32rpx;
            height: 32rpx;
          }
        }
      }
    }
  }
  .mode_type_box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24rpx 32rpx;
    border-bottom: 2rpx solid #EBEDF0;
    box-sizing: border-box;
    &.noNeed_mode_box {
      background-color: #FAFAFA;
      border-bottom: none;
      .mode_type_l {
        color: #969799;
        font-weight: 400;
      }
    }
    .mode_type_l {
      color: #323233;
      font-size: 28rpx;
      line-height: 40rpx;
    }
    .mode_type_r {
      padding: 4rpx 0;
      .img_box {
        display: block;
        width: 32rpx;
        height: 32rpx;
      }
    }
  }
  .logistics_template_box {
    padding: 28rpx 48rpx;
    background: #F7F8FA;
  }
}
.helpSell_content_box {
  background-color: #fff;
  margin-bottom: 16rpx;
  .helpSell_box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24rpx 32rpx;
    flex: 1;
    .helpSell_box_l {
      color: #323233;
      display: flex;
      flex: 1;
      font-weight: bolder;
      align-items: center;
      i {
        width: 116rpx;
        flex: 0 0 auto;
      }
      .span {
        display: inline-block;
        color: #E44435;
        font-size: 24rpx;
      }
      b {
        color: #E44435;
        font-size: 20rpx;
        font-weight: 400;
        margin-left: 8rpx;
      }
    }
    .helpSell_box_r {
      display: flex;
      justify-content: flex-end;
      flex: 0 0 auto;
      width: 320rpx;
      .helpSell_ratio_box {
        display: flex;
        justify-content: center;
        align-items: center;
        color: #323233;
        border: 2rpx solid #DCDEE0;
        font-size: 24rpx;
        padding: 0 16rpx;
        border-radius: 4rpx;
        .input_box {
          width: 80rpx;
          padding: 0 4rpx;
          text-align: center;
          box-sizing: border-box;
        }
      }
    }
  }
}
.tips_popup_box {
	width: 622rpx;
	.tips_popup_title {
		font-size: 32rpx;
    text-align: center;
	}
	.tips_popup_btn {
		border: 2rpx solid #EBEDF0;
		.iKnow_btn {
			width: 100%;
			height: 96rpx;
			font-size: 36rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #E44435;
		}
	}
}
</style>